package com.wanxing.sellerapp.upload;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class ReSyncVideoDelay implements Delayed {

    private final long expire; // 过期时间
    // 重传文件名称
    private final String orderId;

    public ReSyncVideoDelay(String orderId) {
        // 默认3秒后重传
        this.expire = System.currentTimeMillis() + 3 * 1000;
        this.orderId = orderId;
    }

    public ReSyncVideoDelay(long delayTime, String orderId) {
        this.expire = System.currentTimeMillis() + delayTime;
        this.orderId = orderId;
    }

    @Override
    public long getDelay(@NotNull TimeUnit timeUnit) {
        return timeUnit.convert(this.expire - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(@NotNull Delayed o) {
        long f = this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
        return (int) f;
    }

    public String getOrderId() {
        return orderId;
    }

}
